package com.vrview.administrator.fresco;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import com.facebook.binaryresource.BinaryResource;
import com.facebook.binaryresource.FileBinaryResource;
import com.facebook.cache.common.CacheKey;
import com.facebook.drawee.backends.pipeline.Fresco;
import com.facebook.drawee.interfaces.DraweeController;
import com.facebook.drawee.view.SimpleDraweeView;
import com.facebook.imagepipeline.cache.DefaultCacheKeyFactory;
import com.facebook.imagepipeline.core.ImagePipelineFactory;
import com.facebook.imagepipeline.request.ImageRequest;
import com.facebook.imagepipeline.request.ImageRequestBuilder;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URI;

public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

    private ListView listView;
    private String[] imageUrls = Images.imageUrl;
    private ImageAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        initView();
    }

    private void initView() {
//        Uri uri = Uri.parse("http://img4.imgtn.bdimg.com/it/u=1906744648,758477532&fm=21&gp=0.jpg");
//        SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.user_avator);
//
//        draweeView.setImageURI(uri);
//
//        DraweeController controller = Fresco.newDraweeControllerBuilder()
//                .setUri(uri)
//                .setTapToRetryEnabled(true)
//                .setOldController(draweeView.getController())
//                .build();
//        draweeView.setController(controller);
        listView = (ListView) findViewById(R.id.listView);
        adapter = new ImageAdapter(this,listView,imageUrls);
        listView.setAdapter(adapter);
        listView.setOnItemClickListener(this);

    }

    public void cleanCache(View view){
        ImagePipelineConfigFactory.cleanCacheFromMobilePhon();
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

    }
}
